<!-- .vitepress/theme/Layout.vue -->
<template>
  <Layout>
    <template #sidebar-top>
      <!-- 搜索 -->
      <SearchBar @onEvent="SearchEvent"
                 :words="keywords" />
    </template>
  </Layout>
  <!-- <Content /> make sure to include markdown outlet -->
</template>
<script>
// import 'quick-plugin-md/styles/index.css'
import { useRouter, useData } from 'vitepress'

import DefaultTheme from 'vitepress/theme';
const Layout = DefaultTheme.Layout
/**
 * 搜索根目下的全局数据
 */
import keywords from "../../../keywords.json";

export default {
  components: { Layout },
  setup () {

    const { site } = useData()

    /** 路由 */
    const router = useRouter();
    /** 搜索事件触发 */
    const SearchEvent = (data) => {
      // 发布根目录
      let _url = site.value.base + data.url.substr(1);
      // let _url = data.url.substr(1);
      // let _url = data.url;
      console.log('SearchEvent：', _url);
      router.go(_url);
    };

    return { keywords, SearchEvent }
  }
}
</script>

<style lang="less">
.sidebar {
  width: 16rem !important;

  .sidebar-link-item {
    font-size: 0.8rem !important;
  }
}
</style>